/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Prestahop_retrievement;

import com.insa.a1.hibernate.ps.PsAddress;
import com.insa.a1.xmladapter.DateAdapter;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import org.eclipse.persistence.oxm.annotations.XmlInverseReference;

/**
 *
 * @author strokyl
 */
@Entity
public class Address implements Serializable {

	@Id
	private int idAdress;

	private String country;
	private String firstName;
	private String lastName;
	private String city;
	private String address;
	private String other;
	private String postCode;
	private String phoneMobile;
	private String company;

	@Temporal(TemporalType.TIMESTAMP)
	@XmlJavaTypeAdapter(DateAdapter.class)
	private Date dateUppAdd;

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "id_customer")
	@XmlInverseReference(mappedBy = "addresses")
	private Customer customer;

	public Address() {
	}

	public Address(PsAddress ps, Customer customer) {
		this.idAdress = ps.getIdAddress();
		this.country = ps.getCountry().getDefaultCountryName();
		this.firstName = ps.getFirstname();
		this.lastName = ps.getLastname();
		this.address = ps.getAddress1() + ps.getAddress2();
		this.other = ps.getOther();
		this.postCode = ps.getPostcode();
		this.phoneMobile = ps.getPhoneMobile();
		this.company = ps.getCompany();
		this.dateUppAdd = ps.getDateUpd();
		this.city = ps.getCity();
		this.customer = customer;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public Customer getCustomer() {
		return customer;
	}

	public void setCustomer(Customer customer) {
		this.customer = customer;
	}

	public String getCity() {
		return city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public String getCompany() {
		return company;
	}

	public void setCompany(String company) {
		this.company = company;
	}

	public String getCountry() {
		return country;
	}

	public void setCountry(String country) {
		this.country = country;
	}

	public Date getDateUppAdd() {
		return dateUppAdd;
	}

	public void setDateUppAdd(Date dateUppAdd) {
		this.dateUppAdd = dateUppAdd;
	}

	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public int getIdAdress() {
		return idAdress;
	}

	public void setIdAdress(int idAdress) {
		this.idAdress = idAdress;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public String getOther() {
		return other;
	}

	public void setOther(String other) {
		this.other = other;
	}

	public String getPhoneMobile() {
		return phoneMobile;
	}

	public void setPhoneMobile(String phoneMobile) {
		this.phoneMobile = phoneMobile;
	}

	public String getPostCode() {
		return postCode;
	}

	public void setPostCode(String postCode) {
		this.postCode = postCode;
	}

	@Override
	public String toString() {
		return String.format("Address( %s , %s , %s , %s)", firstName, lastName, address, city);
	}

	public Date getLastUpdateDate() {
		return dateUppAdd;
	}

}
